//
//  SCWishInfoHeaderView.m
//  Mutal
//
//  Created by TonyStart on 16/10/27.
//  Copyright © 2016年 com.wx. All rights reserved.
//

#import "SCWishInfoHeaderView.h"

#import "SDWebImageManager.h"
@interface SCWishInfoHeaderView()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollerView;
@property (weak, nonatomic) IBOutlet UILabel *wishTitleLabel;
@property (weak, nonatomic) IBOutlet UIButton *wishPicView;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *totalPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *remainingDayLabel;
@property (weak, nonatomic) IBOutlet UILabel *haveRewardPriceLabel;

@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *percentageLabel;
@property (weak, nonatomic) IBOutlet UILabel *supportNumLabel;

@end
@implementation SCWishInfoHeaderView

-(void)awakeFromNib{
    [super awakeFromNib];
    
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 150)];
    
    imgView.image = [UIImage imageNamed:@"wish_default"];
    
    [_scrollerView addSubview:imgView];
}

-(void)setWish:(SCWishModel *)wish{
    _wish=wish;
    
    if (_wish) {
        [self setupContent];
    }
}

-(void)setupContent{
    _wishTitleLabel.text = self.wish.wish_title;
    
    NSString *picUrl = [NSString stringWithFormat:@"http://www.scxxhs.com/huzhu%@",self.wish.avatar];
    
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:picUrl] options:SDWebImageCacheMemoryOnly progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
 
        if (image) {
             [_wishPicView setImage:image forState:UIControlStateNormal];
        }else{
            [_wishPicView setImage:[UIImage imageNamed:@"默认头像"] forState:UIControlStateNormal];
        }
    }];
    
    _userNameLabel.text = self.wish.user_nicename;
    
    _totalPriceLabel.text = [NSString stringWithFormat:@"求打赏%ld",[self.wish.wish_price integerValue]];
    
    CGFloat haveRewardPrice = round([self.wish.wish_reward_price doubleValue]);
    CGFloat totalPrice = [self.wish.wish_price doubleValue];
    
    
    CGFloat percentageValue = haveRewardPrice / totalPrice;
    self.progressView.progress = percentageValue;
    
    self.percentageLabel.text = [NSString stringWithFormat:@"%0.0lf%%",percentageValue*100];
    
    self.haveRewardPriceLabel.text =[NSString stringWithFormat:@"已打赏¥%0.0lf",round([self.wish.wish_reward_price doubleValue])] ;
    
    self.supportNumLabel.text = [NSString stringWithFormat:@"已支持%@",self.wish.wish_reward_num];
    
    self.remainingDayLabel.text = @"剩余XX天";
}
@end
